<template>
	<view class="flex flex-col h-screen">
		<NavBarVue title="设置"></NavBarVue>
		<view class="flex-1 overflow-hidden">
			<FromList title="账号设置" @click="handleEdit">
				<uni-icons type="right" size="20"></uni-icons>
			</FromList>
			<FromList title="我要反馈" @click="handleReport">
				<uni-icons type="right" size="20"></uni-icons>
			</FromList>
			<FromList title="隐私政策" @click="handleGoAgree(1)">
				<uni-icons type="right" size="20"></uni-icons>
			</FromList>
			<FromList title="注册协议" @click="handleGoAgree(2)">
				<uni-icons type="right" size="20"></uni-icons>
			</FromList>
			<FromList title="账号注销" @click="handleCancel">
				<uni-icons type="right" size="20"></uni-icons>
			</FromList>
			<!-- <FromList title="退出登录" @click="onOutLogin">
				<uni-icons type="right" size="20"></uni-icons>
			</FromList> -->
		</view>
		<view class="pb-40">
			<view class="flex justify-center rounded-full p-20 logout mx-20" @click="onOutLogin">退出登录</view>
		</view>
		<uni-popup ref="confirmDialogRef" type="dialog">
			<uni-popup-dialog type="warn" cancelText="取消" confirmText="确定注销" title="提示"
				content="注销账号会清空所有信息和数据，您真的要注销吗?" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		onShow
	} from "@dcloudio/uni-app"
	import FromList from '@/components/FromList.vue';
	import {
		logoutTIM
	} from "@/apis/IM.js"
	const confirmDialogRef = ref(false)
	const isAch = uni.getStorageSync('user').ach

	// 
	const handleEdit = () => {
		if (isAch == 1) {
			uni.navigateTo({
				url: `/pages/user/anchorinfo`
			})
		} else {
			uni.navigateTo({
				url: `/pages/user/userinfo`
			})
		}
	}
	// 我要反馈
	const handleReport = () => {
		uni.navigateTo({
			url: `/pages/test/report?title=问题反馈&type=1`
		})
	}
	const handleGoAgree = (type) => {
		uni.navigateTo({
			url: `/pages/views/webview?type=${type}`
		})
	}
	const handleCancel = () => {
		confirmDialogRef.value.open()
	}
	const dialogConfirm = () => {
		uni.clearStorageSync()
		uni.reLaunch({
			url: "/pages/login/login"
		})
	}

	const dialogClose = () => {
		confirmDialogRef.value.close()
	}
	// 退出登录
	const onOutLogin = async () => {
		const res = await logoutTIM()
		console.log(res);
		uni.clearStorageSync()
		uni.reLaunch({
			url: "/pages/login/login"
		})
	}
</script>

<style lang="scss" scoped>
	.logout {
		background: #ffd7aa;
		color: #7e512c;
	}
</style>